<template>
	<view class="container">
		<!-- 支付金额 -->
		<view class="amount-section">
			<view class="title">支付金额</view>
			<view class="amount">¥{{ orderAmount }}</view>
		</view>
		
		<!-- 支付方式 -->
		<view class="payment-methods">
			<view class="section-title">支付方式</view>
			<view class="method-list">
				<view class="method-item" 
					v-for="(method, index) in paymentMethods" 
					:key="index"
					@click="selectPaymentMethod(index)"
					:class="{ 'active': index === selectedMethod }">
					<view class="method-info">
						<image :src="method.icon" mode="aspectFit"></image>
						<text>{{ method.name }}</text>
					</view>
					<view class="radio">
						<view class="radio-inner" v-if="index === selectedMethod"></view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 底部支付按钮 -->
		<view class="footer">
			<view class="pay-btn" @click="pay">立即支付</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			orderId: '',
			orderAmount: 0,
			paymentMethods: [
				{
					name: '微信支付',
					icon: '/static/payment/wechat.png'
				},
				{
					name: '支付宝支付',
					icon: '/static/payment/alipay.png'
				},
				{
					name: '银联支付',
					icon: '/static/payment/unionpay.png'
				}
			],
			selectedMethod: 0
		}
	},
	onLoad(options) {
		if (options.orderId) {
			this.orderId = options.orderId
			this.getOrderInfo()
		}
	},
	methods: {
		getOrderInfo() {
			// 模拟获取订单信息
			setTimeout(() => {
				this.orderAmount = 135.6
			}, 500)
		},
		selectPaymentMethod(index) {
			this.selectedMethod = index
		},
		pay() {
			if (this.selectedMethod < 0) {
				uni.showToast({
					title: '请选择支付方式',
					icon: 'none'
				})
				return
			}
			
			uni.showLoading({
				title: '正在支付...'
			})
			
			// 模拟支付过程
			setTimeout(() => {
				uni.hideLoading()
				
				uni.showToast({
					title: '支付成功',
					icon: 'success',
					duration: 2000,
					success: () => {
						setTimeout(() => {
							uni.redirectTo({
								url: '/pages/order/success?orderId=' + this.orderId
							})
						}, 2000)
					}
				})
			}, 1500)
		}
	}
}
</script>

<style lang="scss">
.container {
	padding-bottom: 120rpx;
	background-color: #f5f5f5;
}

.amount-section {
	background-color: #fff;
	padding: 60rpx 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	margin-bottom: 20rpx;
	
	.title {
		font-size: 30rpx;
		color: #666;
		margin-bottom: 20rpx;
	}
	
	.amount {
		font-size: 60rpx;
		color: #333;
		font-weight: bold;
	}
}

.payment-methods {
	background-color: #fff;
	padding: 30rpx;
	
	.section-title {
		font-size: 30rpx;
		color: #333;
		margin-bottom: 30rpx;
	}
	
	.method-list {
		.method-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 0;
			border-bottom: 1px solid #f5f5f5;
			
			&:last-child {
				border-bottom: none;
			}
			
			.method-info {
				display: flex;
				align-items: center;
				
				image {
					width: 60rpx;
					height: 60rpx;
					margin-right: 20rpx;
				}
				
				text {
					font-size: 28rpx;
					color: #333;
				}
			}
			
			.radio {
				width: 36rpx;
				height: 36rpx;
				border-radius: 50%;
				border: 2rpx solid #ddd;
				display: flex;
				justify-content: center;
				align-items: center;
				
				.radio-inner {
					width: 18rpx;
					height: 18rpx;
					border-radius: 50%;
					background-color: #ff5151;
				}
			}
			
			&.active {
				.radio {
					border-color: #ff5151;
				}
			}
		}
	}
}

.footer {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	height: 100rpx;
	background-color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 30rpx;
	box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.05);
	
	.pay-btn {
		width: 90%;
		height: 80rpx;
		background-color: #ff5151;
		color: #fff;
		border-radius: 40rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
	}
}
</style> 